Skip to content

feat: consume v2 estimated aprs from kong#561

Merged
matheus1lva merged 4 commits intomainfrom
feat/v2-aprs
Feb 2, 2026
Merged

feat: consume v2 estimated aprs from kong#561
matheus1lva merged 4 commits intomainfrom
feat/v2-aprs

Conversation

@matheus1lva
Copy link
Collaborator

@matheus1lva matheus1lva commented Jan 26, 2026

Summary

This PR integrates Kong's pre-computed estimated APRs into yDaemon for V2 vaults with Curve, Convex, Velodrome, and Aerodrome strategies. The implementation prioritizes Kong's estimated APR data over local RPC-based calculations, reducing RPC call volume and improving performance while maintaining full backward compatibility with the existing API.

Closes #560

How to review

  1. Type definitions: Start with internal/models/vaults.go and internal/kong/client.go to review the new TKongEstimatedApr and TKongEstimatedAprComponents types
  2. GraphQL query updates: Check internal/kong/client.go for the expanded performance.estimated query
  3. Data extraction: Review internal/indexer/indexer.kong.go to see how estimated APR data is extracted from Kong responses
  4. Storage accessor: Check internal/storage/elem.vaults.go for the new GetKongEstimatedAPY() function
  5. Priority logic: Review processes/apr/main.go to see the Kong-first fallback pattern for Curve and Velo vaults
  6. Conversion helper: Check processes/apr/forward.curve.helpers.go for convertKongEstimatedAprToForwardAPY()
  7. Documentation: Review docs/apr-oracle-integration.md for the new V2 integration section

Test plan

Manual testing

Verified integration with live yDaemon instance:

Query vault on Ethereum mainnet (Curve vault):

curl -s http://localhost:8080/1/vaults/0xf165a634296800812B8B0607a75DeDdcD4D3cC88 | jq '{address, name: .token.name, type: .apr.forwardAPR.type, netAPR: .apr.forwardAPR.netAPR, composite: .apr.forwardAPR.composite}'

Result:

{
  "address": "0xf165a634296800812B8B0607a75DeDdcD4D3cC88",
  "name": "reUSD/scrvUSD",
  "type": "crv",
  "netAPR": 0.04918341021632009,
  "composite": {
    "boost": 2.2711417165483674,
    "poolAPY": 0.008,
    "boostedAPR": 0.04620378912924455,
    "baseAPR": 0.03806021027585871,
    "cvxAPR": 0,
    "rewardsAPR": 0
  }
}

Verify Kong source data:

curl -s "https://kong.yearn.farm/api/gql" -H "Content-Type: application/json" -d '{"query":"query { vault(chainId: 1, address: \"0xf165a634296800812B8B0607a75DeDdcD4D3cC88\") { address performance { estimated { apr apy type components { boost poolAPY boostedAPR baseAPR rewardsAPY cvxAPR keepCRV } } } } }"}' | jq '.data.vault.performance.estimated'

Kong response (matches yDaemon output exactly):

{
  "apr": 0.04918341021632009,
  "apy": 0.04918341021632009,
  "type": "crv",
  "components": {
    "boost": 2.2711417165483674,
    "poolAPY": 0.008,
    "boostedAPR": 0.04620378912924455,
    "baseAPR": 0.03806021027585871,
    "rewardsAPY": 0,
    "cvxAPR": 0,
    "keepCRV": 0
  }
}

Verification: yDaemon successfully consumes Kong's estimated APR data. All values match exactly, confirming the integration works as expected.

  • Manual: Tested with live yDaemon instance on chain 1
  • Verified Kong data source matches yDaemon output
  • Confirmed backward compatibility (API response structure unchanged)

…rome vaults

Replace local RPC-based forward APR calculations with pre-computed estimated APRs from Kong's GraphQL API for V2 vaults. This integration reduces RPC call volume and improves performance while maintaining full backward compatibility.

Changes:
- Add TKongEstimatedApr and TKongEstimatedAprComponents types to Kong client and models
- Update Kong GraphQL queries to fetch performance.estimated field with all components
- Extract and store estimated APR data in Kong indexer
- Add GetKongEstimatedAPY() storage accessor function
- Modify forward APY calculation to prioritize Kong data with graceful fallback to local computation
- Update apr-oracle-integration.md with V2 estimated APR integration documentation

Supported chains: Ethereum (1), Optimism (10), Fantom (250), Arbitrum (42161), Base (8453)
Supported strategies: Curve, Convex, Velodrome, Aerodrome

Implements: #560
@matheus1lva matheus1lva changed the title Consume Kong estimated APRs for V2 Curve/Convex/Velodrome/Aerodrome vaults feat: consume v2 estimated aprs from kong Jan 26, 2026
@murderteeth murderteeth self-requested a review January 27, 2026 05:47
Copy link
Collaborator

@murderteeth murderteeth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • build and run ydaemon in dev
  • configure main branch yearn.fi to point at local ydaemon
  • compare est apy's from v2 vault list in yearn.fi local dev with yearn.fi live
  • some look good, but i also see differences that can't be explained by timing differences. implementing yearn/v2-estimated-apr-hook#5 may fix some of these
Image

@matheus1lva
Copy link
Collaborator Author

  • build and run ydaemon in dev
  • configure main branch yearn.fi to point at local ydaemon
  • compare est apy's from v2 vault list in yearn.fi local dev with yearn.fi live
  • some look good, but i also see differences that can't be explained by timing differences. implementing yearn/v2-estimated-apr-hook#5 may fix some of these
Image

Yeah that's fair, could be the case.

@matheus1lva
Copy link
Collaborator Author

CleanShot 2026-01-28 at 18 59 56@2x I managed to spin both sides, but something was wrong with my setup that the parsing was wrong despite value being right.

Copy link
Collaborator

@murderteeth murderteeth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Est. APY still doesn't match. yearn.fi is on the left, localhost is on the right,
Image

i'll share my localhost .env in dm

@murderteeth
Copy link
Collaborator

Est. APY still doesn't match. yearn.fi is on the left, localhost is on the right, Image

i'll share my localhost .env in dm

this looks like a problem in the v2 estimated apr service to me @matheus1lva. i see a zero apr for ycrv here too

curl https://kong.yearn.fi/api/rest/snapshot/1/0x27B5739e22ad9033bcBf192059122d163b60349D | jq '.performance'

{
  "estimated": {
    "apr": 0,
    "apy": 0,
    "type": "crv",
    "components": {
      "boost": 0,
      "cvxAPR": 0,
      "baseAPR": 0,
      "keepCRV": 0,
      "poolAPY": 0,
      "keepVelo": null,
      "boostedAPR": 0,
      "rewardsAPR": 0,
      "rewardsAPY": 0
    }
  },
  "historical": {
    "net": 0.22221062887397403,
    "weeklyNet": 0.3190767354640722,
    "monthlyNet": 0.22221062887397403,
    "inceptionNet": 0.28758355635049293
  }
}

@matheus1lva
Copy link
Collaborator Author

CleanShot 2026-02-01 at 12 59 50@2x So got it testing against local. Despite the %'s not being 100% =, i did a few local iterations with claude and we compared live curve api with results from ydaemon and the difference was because of a cache on ydaemon apparently.

The calculations achieved over fapy-hook were correctly returned and the values from curve endpoints were also more accurate, so that's the gist. I got worried about this but went straight debug and that made sense.

@murderteeth murderteeth self-requested a review February 2, 2026 17:44
@matheus1lva matheus1lva merged commit cad4086 into main Feb 2, 2026
3 checks passed
@matheus1lva matheus1lva deleted the feat/v2-aprs branch February 2, 2026 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consume estimated V2 APRs from Kong into yDaemon

2 participants